<?php
class ExpenditureDistributionsController extends AppController {
    var $name = 'ExpenditureDistributions';

    function index() {
        $this->ExpenditureDistribution->recursive = 0;
        $this->set('expenditureDistributions', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid expenditure distribution', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('expenditureDistribution', $this->ExpenditureDistribution->read(null, $id));
    }

    function add() {
        if (!empty($this->data)) {
            $this->ExpenditureDistribution->create();
            if ($this->ExpenditureDistribution->save($this->data)) {
                $this->Session->setFlash(__('The expenditure distribution has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The expenditure distribution could not be saved. Please, try again.', true));
            }
        }
        $propertyTypes = $this->ExpenditureDistribution->PropertyType->find('list');
        $expenditureTypes = $this->ExpenditureDistribution->ExpenditureType->find('list');
        $this->set(compact('propertyTypes', 'expenditureTypes'));
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid expenditure distribution', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->ExpenditureDistribution->save($this->data)) {
                $this->Session->setFlash(__('The expenditure distribution has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The expenditure distribution could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->ExpenditureDistribution->read(null, $id);
        }
        $propertyTypes = $this->ExpenditureDistribution->PropertyType->find('list');
        $expenditureTypes = $this->ExpenditureDistribution->ExpenditureType->find('list');
        $this->set(compact('propertyTypes', 'expenditureTypes'));
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for expenditure distribution', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->ExpenditureDistribution->delete($id)) {
            $this->Session->setFlash(__('Expenditure distribution deleted', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->Session->setFlash(__('Expenditure distribution was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }
}
?>
